home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: uu4news.netcom.com!zodiac!szh
- From: szh@zcon.com (Syed Zaeem Hosain)
- Subject: Re: A Very Simple Socket Question
- Message-ID: <1996Jan16.174631.1892@zcon.com>
- Sender: szh@zcon.com (Syed Zaeem Hosain)
- Nntp-Posting-Host: zodiac
- Reply-To: szh@zcon.com
- Organization: Z Consulting Group
- References: <4dfgj8$6p9@nntp.ucs.ubc.ca>
- Date: Tue, 16 Jan 1996 17:46:31 GMT
-
- In article <4dfgj8$6p9@nntp.ucs.ubc.ca>, evil@unixg.ubc.ca (Peter Pan) writes:
- >Please help! I am a C beginner.
- >
- >======================================
- >Client:
- >
- >int sd, addrlen;
- >struct sockaddr_in svaddr;
- >
- >char *data;
- >data = "abcdef";
- >
- >..... /* skip */
- >
- >sendto(sd, data, strlen(data), 0, &svaddr, &addrlen);
- >
- >
- >==========================================
- >Server:
- >
- >char data;
- >data = (char*) malloc( 100*sizeof(char) );
- >
- >recvfrom(sd2, data, sizeof(data), 0, &claddr, &addrlen);
- >
- >==========================================
- >
- >Output:
- >
- >data sent: abcdef
- >data received: abcd
- >
- >==========================================
- >
- >Anyone knows why the data are different after transmittion.
-
- Well, I do not know if this is the problem (it may be a typo in your
- post), but you might try declaring:
-
- char *data;
-
- on the server, rather than:
-
- char data;
-
- When you then assign "data = (char *) mall...", the very explicit cast
- *probably* (but I am not sure) causes the error messages about this
- mistake to be suppressed.
-
- Of course, there may still be something more wrong with the socket
- transmission. But this is one place to get started.
-
- Z
-
-
- --
- -------------------------------------------------------------------------
- | Syed Zaeem Hosain P. O. Box 610097 (408) 441-7021 |
- | Z Consulting Group San Jose, CA 95161 szh@zcon.com |
- -------------------------------------------------------------------------
-